package xyz.yuzegod.megawalls.classes.mythic.werewolf;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;

import java.util.ArrayList;
import java.util.List;

public class MainSkill extends Skill
{
    public MainSkill(final Classes classes) {
        super("狼人变身", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 5;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 3.2;
            }
            case 2: {
                return 4.4;
            }
            case 3: {
                return 5.6;
            }
            case 4: {
                return 6.8;
            }
            case 5: {
                return 8.0;
            }
            default: {
                return 3.2;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7获得持续§a" + this.getAttribute(level) + "§7秒的速度 II 效果。");
            lore.add("   §7在这期间,你会恢复你造成伤害的30%");
            lore.add("   §7并且攻击敌人时造成2点真实伤害");
            return lore;
        }
        lore.add(" §8▪ §7获得持续§8" + this.getAttribute(level - 1) + " ➜ §a" + this.getAttribute(level) + "§7秒的速度 II 效果。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkillLevel();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkillLevel();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        final Player player = gamePlayer.getPlayer();
        if (player.hasPotionEffect(PotionEffectType.SPEED)) {
            player.removePotionEffect(PotionEffectType.SPEED);
        }
        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, (int)this.getAttribute(this.getPlayerLevel(gamePlayer)) * 20, 1));
        Werewolf.skill.add(gamePlayer);
        Bukkit.getScheduler().runTaskLater((Plugin)MegaWalls.getInstance(), (Runnable)new Runnable() {
            @Override
            public void run() {
                Werewolf.skill.remove(gamePlayer);
                Werewolf.skillDamage.remove(gamePlayer);
            }
        }, (long)this.getAttribute(this.getPlayerLevel(gamePlayer)) * 20L);
        return true;
    }
}
